package com.cskaoyan.utils;

import java.io.*;

/**
 * @description:
 * @author: 景天
 * @date: 2023/2/17 17:45
 **/

// 工具类
public class FileUtils {
    // 提供文件复制的方法

    //public static void copy1(FileInputStream in, FileOutputStream out) {
    //    // 单字节复制操作
    //}
    //
    //public static void copy2(FileInputStream in, FileOutputStream out) {
    //    // 多字节复制操作
    //}
    //
    //
    //public static void copy3(BufferedInputStream in, BufferedOutputStream out) {
    //    // 单字节复制操作
    //}
    //
    //
    //public static void copy4(BufferedInputStream in, BufferedOutputStream out) {
    //    // 多字节复制操作
    //}

    // 单字节复制
    public static void copy1(InputStream in, OutputStream out) throws IOException{
        int readData;
        while ((readData = in.read()) != -1) {
            // 写入操作
            out.write(readData);
        }
    }

    // 多字节复制
    public static void copy2(InputStream in, OutputStream out) throws IOException{
        int readCount;
        byte[] bytes = new byte[1024];
        while (( readCount = in.read(bytes)) != -1) {
            // 写操作
            out.write(bytes, 0, readCount);
        }
    }

    // 单字符复制
    public static void copy3(Reader reader,Writer writer) throws IOException{
        int readData;
        while ((readData = reader.read()) != -1) {
            writer.write(readData);
        }

    }


    // 字符数组方式赋值
    public static void copy4(Reader reader,Writer writer) throws IOException{
        int readCount;
        // 字符数组
        char[] chars = new char[1024];

        while ((readCount = reader.read(chars)) != -1) {
            writer.write(chars,0,readCount);
        }

    }

}
